<% layout('/layouts/default.html', {title: '商品管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> ${text('商品管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('natatoriumgoods:natatoriumGoods:edit')){ %>
					<a href="${ctx}/natatoriumgoods/natatoriumGoods/form?natatoriumInfoId=${cookie('natatoriumInfoId')}" class="btn btn-default btnTool" title="${text('新增游泳馆商品')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${natatoriumGoods}" action="${ctx}/natatoriumgoods/natatoriumGoods/listData?natatoriumInfoId=${cookie('natatoriumInfoId')}" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('商品名称')}：</label>
					<div class="control-inline">
						<#form:input path="name" maxlength="500" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('商品类型')}：</label>
					<div class="control-inline width-120">
						<#form:select path="goodsType" dictType="goods_type" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('商品状态')}：</label>
					<div class="control-inline width-120">
						<#form:select path="goodsStatus" dictType="goods_status" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
var goodsStatus;
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text('商品名称')}', name:'name', index:'a.name', width:200, align:"center"},
		{header:'${text('商品类型')}', name:'goodsType', index:'a.goods_type', width:100, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('goods_type')}, val, '${text('未知')}', true);
		}},
		{header:'${text('单价')}', name:'price', index:'a.price', width:150, align:"center", formatter: function(val, obj, row, act){
			return "￥"+js.formatNumber(val, 2, false, ''); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
		}},
		{header:'${text('库存数量')}', name:'number', index:'a.number', width:100, align:"center"},
		{header:'${text('已售数量')}', name:'sellNumber', index:'a.sell_number', width:100, align:"center"},
		{header:'${text('上架时间')}', name:'upSellTime', index:'a.up_sell_time', width:200, align:"center"},
		{header:'${text('下架时间')}', name:'downSellTime', index:'a.down_sell_time', width:200, align:"center"},
		{header:'${text('商品状态')}', name:'goodsStatus', index:'a.goods_status', width:100, align:"center", formatter: function(val, obj, row, act){
			goodsStatus = val;
			return js.getDictLabel(${@DictUtils.getDictListJson('goods_status')}, val, '${text('未知')}', true);
		}},
		{header:'${text('操作')}', name:'actions', width:220, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			if (goodsStatus == 1){
				actions.push('<a href="${ctx}/natatoriumgoods/natatoriumGoods/updateGoodsStatus?natatoriumGoodsId='+row.id+'&goodsStatus=2" class="btn btnList btn-operation" title="${text("上架")}" data-confirm="${text("确认上架该商品吗？")}">上架</a>');					
			}	
			if (goodsStatus == 2){
				actions.push('<a href="${ctx}/natatoriumgoods/natatoriumGoods/updateGoodsStatus?natatoriumGoodsId='+row.id+'&goodsStatus=1" class="btn btnList btn-operation" title="${text("下架")}" data-confirm="${text("确认下架该商品吗？")}">下架</a>');
			}
			actions.push('<a href="${ctx}/natatoriumgoods/natatoriumGoods/details?id='+row.id+'" class="btn btnList btn-operation" title="查看详情">${text("查看")}</a>&nbsp;&nbsp;');
			actions.push('<a href="${ctx}/natatoriumgoods/natatoriumGoods/form?id='+row.id+'" class="btnList btn-operation" title="${text('编辑基本信息')}">${text("编辑")}</a>&nbsp;');
			actions.push('<a href="${ctx}/natatoriumgoods/natatoriumGoods/delete?id='+row.id+'" class="btn btnList btn-operation" title="${text('删除商品')}" data-confirm="${text('确认要删除该商品吗？')}">删除</a>&nbsp;');
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>